package com.parse.starter;

import com.parse.ParseException;
import com.parse.ParseUser;


import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity {

   private Button login;
   private EditText uname;
   private EditText password;
   
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_login);
      login = (Button) findViewById(R.id.loginButton);
      uname = (EditText) findViewById(R.id.usernameET);
      uname.setText("Kevin");
      password = (EditText) findViewById(R.id.passwordET);
      password.setText("password");
      login.setOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View view) {
            try {
               ParseUser.logIn(uname.getText().toString(), password.getText().toString());
               nextScreen();
            } catch (ParseException e) {
               loginFail();
            }
         }
      });
   }

   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.login, menu);
      return true;
   }

   public void loginFail() {
      Toast.makeText(this, "Login failed.", Toast.LENGTH_SHORT).show();
   }
   public void nextScreen() {
      android.content.Intent thought = new android.content.Intent(this, MainActivity.class);
      this.startActivity(thought);
   }
}
